package com.example.fw;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


public class Contacts {

	private Set<ContactObject> storedContacts = null;
	
	public Contacts (Collection<ContactObject> contacts)	{
		storedContacts = new HashSet<ContactObject>(contacts);
	}
	
	public Contacts withAdded(ContactObject contact) {
		Contacts contacts = new Contacts(storedContacts);
		contact.setContactId("$$$");
		contacts.storedContacts.add(contact);
		contact.setContactId(null);
		return contacts;
	}

	public Contacts withOut(ContactObject contact) {
		Contacts contacts = new Contacts(storedContacts);
		contacts.storedContacts.remove(contact);
		return contacts;
	}
	
	public ContactObject takeSomeContactFromList() {		//Groups groupList
		Contacts contacts = new Contacts(storedContacts);
		ContactObject someContactFromList = contacts.storedContacts.iterator().next();
		return someContactFromList;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((storedContacts == null) ? 0 : storedContacts.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Contacts other = (Contacts) obj;
		if (storedContacts == null) {
			if (other.storedContacts != null)
				return false;
		} else if (!storedContacts.equals(other.storedContacts))
			return false;
		return true;
	}
}
